<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="IDValidator.js" charset="utf-8" ></script>
<script type="text/javascript" src="GB2260.js" charset="utf-8" ></script>
<title>JS查询身份证信息</title>
<style type="text/css">
html{
	position: absolute;
	top: 30%;
	left: 40%;
	
}
div{
	margin: 20px;
}
</style>
<script type="text/javascript">

var Validator = new IDValidator();

$(function (){
	$("#isValid-btn").click(function (){
		var code = $("#isValid").val();
		var i = Validator.isValid(code);
		$("#isValid-show").html(i == false ? "号码不合法" : "号码合法");
	});
	$("#getInfo-btn").click(function (){
		var code = $("#getInfo").val();
		var i = Validator.getInfo(code);
		if(i == false){
			$("#getInfo-show").html("号码不合法！！！");
		}else{
			var obj = eval('(' + JSON.stringify(i) + ')');
			function ages(str) {
				var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
				if(r==null) return false;
				var d = new Date(r[1], r[3]-1, r[4]);
				if(d.getFullYear() == r[1]&&(d.getMonth()+1) == r[3]&&d.getDate() == r[4]) {
					var Y = new Date().getFullYear();
					return((Y-r[1]) + " 周岁");
				}
				return("输入的日期格式错误！！！");
			}

			$("#getInfo-show").html("行政区编号：" + obj.addrCode + "<br />" + "户籍所在地：" + obj.addr + "<br />" +
		"出生年月日：" + obj.birth + "<br />" + "性别：" + obj.sex + "<br />" + "身份证长度：" + obj.length
			+ "<br />" + "校验位:" + obj.checkBit + "<br />" + "年龄：" + ages(obj.birth));
		}
	});
	$("#makeID18-btn").click(function (){
		$("#makeID18-show").html(Validator.makeID());
	});
	$("#makeID15-btn").click(function (){
		$("#makeID15-show").html(Validator.makeID(true));
	});
});
</script>
</head>
<body>
<div>
	<input id="isValid" />
	<button id="isValid-btn">判断是否合法</button>
	<div id="isValid-show"></div>
</div>
<div>
	<input id="getInfo" />
	<button id="getInfo-btn">身份证详细信息</button>
	<div id="getInfo-show"></div>
</div>
<div>
	<button id="makeID18-btn">仿造一个18位身份证号</button>
	<div id="makeID18-show"></div>
</div>
<div>
	<button id="makeID15-btn">仿造一个15位身份证号</button>
	<div id="makeID15-show"></div>
</div>
</body>
</html>